home *** CD-ROM | disk | FTP | other *** search
- ///////////////////////////////////////////////////////////////////////////////
- //
- // ALU.hxx - Arithmetic Logic Unit
- //
- // By: Bradford W. Mott
- // December 3,1993
- //
- ///////////////////////////////////////////////////////////////////////////////
-
- #ifndef ALU_HXX
- #define ALU_HXX
-
- // ALU Function codes
- enum ALUFunction {
- ADD = 0x00, ADDC = 0x01, SUB = 0x02,
- AND = 0x03, SUBC = 0x04, OR = 0x05,
- XOR = 0x06, CMP = 0x0a, BTST = 0x0b,
- NOT_A = 0x80, NEG_A = 0x81, INC_A = 0x82,
- DEC_A = 0x83, SHL_A = 0x90, ROL_A = 0x91,
- SHR_A = 0x92, ROR_A = 0x93, PASS_A = 0x100,
- SWAP_A = 0x101, ADD_NCC = 0x102, INC_A_NCC = 0x103,
- INC_B_NCC = 0x104, DEC_A_NCC = 0x105, DEC_B_NCC = 0x106,
- A_CC = 0x107, CC_OUT = 0x108, PASS_A_NCC = 0x10a,
- SUB_NCC = 0x10b, DO_NOTHING = 0xffff
- };
-
- // ALU Condition Codes
- enum ALUConditionCode {
- CC_VC = 0, CC_PL = 1, CC_GE = 2, CC_F = 3, CC_LE = 4, CC_NE = 5,
- CC_LS = 6, CC_CC = 7, CC_VS = 8, CC_MI = 9, CC_LT = 10, CC_T = 11,
- CC_GT = 12, CC_EQ = 13, CC_HI = 14, CC_CS = 15
- };
-
- // ALU Flags
- const unsigned long C_FLAG=0x8000;
- const unsigned long V_FLAG=0x4000;
- const unsigned long N_FLAG=0x2000;
- const unsigned long Z_FLAG=0x1000;
- const unsigned long I_FLAG=0x0800;
-
- ///////////////////////////////////////////////////////////////////////////////
- // The Arithmetic Logic Unit
- ///////////////////////////////////////////////////////////////////////////////
- class ALU {
- private:
-
- // ALU flags (16 bits: CVNZI-----------)
- unsigned long flags;
-
- public:
- ALU()
- { flags=I_FLAG; }
-
- ~ALU()
- {}
-
- // Get the ALU's flags
- inline unsigned long GetFlags()
- { return(flags); }
-
- // Set the ALU's flags
- inline void SetFlags(unsigned long value)
- { flags=value & 0xf800; }
-
- // Compute a result with the given operation and inputs
- unsigned long Compute(ALUFunction f, unsigned long a, unsigned long b);
-
- // Test the given Condition Code
- int TestConditionCode(ALUConditionCode cc, const char* &description);
- };
- #endif
-
-